package org.happylearn.jdk.concurrent;

/**
 * 测试Thread.sleep()和Object.wait();
 * @author ljh
 *
 */
public class SleepTest {
	
	public static synchronized void sleep() throws InterruptedException {
		Thread.sleep(2000);
		System.out.println("current sleep thread： "+Thread.currentThread().getName());
		
	}
	
	public static void main(String[] args) throws Exception{
		Thread t1 = new Thread() {
			public void run() {
				try {
					SleepTest.sleep();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}//睡眠1s
			};
			
		};
		
		Thread t2 = new Thread() {
			public void run() {
				try {

					SleepTest.sleep();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			};
			
		};
		
		t1.start();
		t2.start();
		
	
		t1.join();
		t2.join();
		//Thread.sleep(1000*3);
		
		//注意： t1,t2还没有执行完成，main线程退出了
		
	}
}
